package com.ejuornal.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ejuornal.bean.EditorChief;
import com.ejuornal.bean.Page;
import com.ejuornal.dao.EditorChiefDao;
import com.ejuornal.service.EditorChiefService;

@Component("editorChiefService")
public class EditorChiefServiceImpl implements EditorChiefService {
	public EditorChiefDao editorChiefDao;

	public void add(EditorChief editorChief) {
		String sql = "insert into t_editor_chief (userId,businessId,codeId,address,status,businessImg,codeImg) values (?,?,?,?,?,?,?)";
		editorChiefDao
				.add(sql,
						new Object[] { editorChief.getUserId(),
								editorChief.getBusinessId(),
								editorChief.getCodeId(),
								editorChief.getAddress(),
								editorChief.getStatus(),
								editorChief.getBusinessImg(),
								editorChief.getCodeImg() });
	}

	public void updateStatus(EditorChief editorChief) {
		String sql = "update t_editor_chief set status = ? where editorChiefId = ?";
		System.out.println("impl  stat"+editorChief.getStatus());
		editorChiefDao.update(sql, new Object[] { editorChief.getStatus(), editorChief.getEditorChiefId()});
	}

	public void updateInfo(int editorChiefId, EditorChief editorChief) {
		String sql = "update t_editor_chief set businessId = ?, codeId = ?, address = ?,  status = ? ,businessImg = ?,codeImg = ? where editorChiefId = ?";
		editorChiefDao.update(
				sql,
				new Object[] { editorChief.getBusinessId(),
						editorChief.getCodeId(), editorChief.getAddress(),
						editorChief.getStatus(), editorChief.getBusinessImg(),
						editorChief.getCodeImg() });
	}

	public EditorChief findById(int editorChiefId) {
		return editorChiefDao.findById(editorChiefId);
	}
	
	public EditorChief findByUserId(int userId) {
		return editorChiefDao.findByUserId(userId);
	}

	public Page<EditorChief> findByStatus(int current_record,String url, String value) {
	//	String hsql = "where status = ?";
		String  count =" SELECT DISTINCT COUNT(*) FROM t_editor_chief ec ,t_user u WHERE ec.userId = u.userId AND u.roleId !=1 AND ec.`status`= ? ";
		String sql = " SELECT DISTINCT ec.* FROM t_editor_chief ec ,t_user u WHERE ec.userId = u.userId AND u.roleId !=1 AND ec.`status`= ?  limit " + current_record + ", 10 ";
		return editorChiefDao.find(current_record, url, count, sql, new Object[]{value});
	}
	
	@Override
	public boolean killChief(int userId) {
		return editorChiefDao.killChief(userId);
	}
	

	@Override
	public boolean recoverChief(int userId) {
		return editorChiefDao.recoverChief(userId);
	}

	@Override
	public boolean isApplied(int userId) {
		return editorChiefDao.isApplied(userId);
	}
	
	@Override
	public Page<EditorChief> blackChiefList(int current_record,String url) {
		String countsql = " SELECT DISTINCT COUNT(*) FROM  t_editor_chief ec ,t_user u WHERE ec.userId = u.userId AND u.roleId = ?  ";
		String sql = " SELECT DISTINCT ec.* FROM  t_editor_chief ec ,t_user u WHERE ec.userId = u.userId AND u.roleId = ?   limit " + current_record + ", 10 ";
		return editorChiefDao.find(current_record, url, countsql, sql, new Object[]{1});
	}

	/**
	 * 查询所有的未审核主编信息-VO
	 * @param current_record
	 * @param url
	 * @param value
	 * @return
	 *//*
	public Page<User_EditorChief> findChiefVoByStatus(int current_record,String url, String value){
		String  count =" SELECT DISTINCT COUNT(*) FROM t_editor_chief ec ,t_user u WHERE ec.userId = u.userId AND u.roleId !=1 AND ec.`status`= ? ";
		String sql = " SELECT DISTINCT ec.*,u.userName  FROM t_editor_chief ec ,t_user u WHERE ec.userId = u.userId AND u.roleId !=1 AND ec.`status`= ?  limit " + current_record + ", 10 ";
		return editorChiefVoDao.find(current_record, url, count, sql, new Object[]{value});
	}*/
	
	public EditorChiefDao getEditorChiefDaoImpl() {
		return editorChiefDao;
	}

	@Resource(name = "editorChiefDao")
	public void setEditorChiefDao(EditorChiefDao editorChiefDao) {
		this.editorChiefDao = editorChiefDao;
	}
}
